package com.woniuxy.project.campus.util;



import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
public class Result<T> implements Serializable {
    private int code;
    private String message;
    private T data;
    private List<T> list;

    public Result() {}

    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(int code, String message, T data, List<T> list) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.list = list;
    }


    // 成功
    public static <T> Result<T> success(T data) {
        return new Result<>(200, "success", data);
    }

    public static <T> Result<T> success(T data, List<T> list) {
        return new Result<>(200, "success", data, list);
    }

    public static <T> Result<T> success(List<T> list) {
        return new Result<>(200, "success", null, list);
    }

    // 失败
    public static Result<Object> fail(String message) {
        return new Result<>(500, message, null);
    }

    // 自定义错误
    public static Result<Object> loginFail(Integer code, String message) {
        return new Result<>(500, message, null);
    }
}
